package com.yejiarong.common.tools;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author YeJR
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Pagination implements Serializable {

    /**
     * 页码
     */
    @NotNull(message = "pageNo不能为NULL")
    @Min(value = 1, message = "pageNo最小为1")
    private Integer pageNo;

    /**
     * 每页条数
     */
    @NotNull(message = "pageSize不能为NULL")
    @Min(value = 1, message = "pageSize最小为1")
    @Max(value = 1000, message = "pageSize最大为1000")
    private Integer pageSize;


    /**
     * 开始index
     * @return 开始index
     */
    public Integer getFrom() {
        return (pageNo - 1) * pageSize;
    }
}